package View;


import Model.Contact;
import View.addContactView.ItemAction;

import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.JButton;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

public class modifieContactView extends JFrame {
	/**
	 * Fenetre modifier contact
	 */

	private JTextField jtf1;
	private JTextField jtf2;
	private JTextField jtf3;
	private JTextField jtf4;
	private JTextField jtf5;
	private JTextField jtf6;
	private JTextField jtf7;

	private JButton b = new JButton("OK");
	private JButton cancel= new JButton("Annuler");

	private JLabel nom = new JLabel("   Nom:");
	private JLabel prenom = new JLabel("   Prenom:");
	private JLabel adresse = new JLabel("   Adresse:");
	private JLabel addPro = new JLabel("   Adresse professionnel:");
	private JLabel numero = new JLabel("   Numero:");
	private JLabel numPro = new JLabel("   Numero professionnel:");
	private JLabel mail = new JLabel("   Email:");
	private JLabel grp= new JLabel("   Groupe:");
	
	private String[] choixGrp={"Tout","Famille","Amis","Travail"};
	private JComboBox combo=new JComboBox(choixGrp);

	public modifieContactView(Contact cont) {
		jtf1 = new JTextField(cont.getLastName());
		jtf2 = new JTextField(cont.getFirstName());
		jtf3 = new JTextField(cont.getHmAdd());
		jtf4 = new JTextField(cont.getCmpAdd());
		jtf5 = new JTextField(cont.getPhone());
		jtf6 = new JTextField(cont.getProfPhone());
		jtf7 = new JTextField(cont.getMail());
		JPanel pan = new JPanel(new GridLayout(9, 1));

		pan.add(nom);
		pan.add(jtf1);
		pan.add(prenom);
		pan.add(jtf2);
		pan.add(adresse);
		pan.add(jtf3);
		pan.add(addPro);
		pan.add(jtf4);
		pan.add(numero);
		pan.add(jtf5);
		pan.add(numPro);
		pan.add(jtf6);
		pan.add(mail);
		pan.add(jtf7);
		combo.setPreferredSize(new Dimension(100,20));
		pan.add(grp);
		pan.add(combo);
		pan.add(b);
		pan.add(cancel);


		//ajout d'un listener sur la comboBox

		combo.addActionListener(new ItemAction());
		
		this.setBounds(0, 0, 300, 300);
		this.setLocationRelativeTo(null);
		this.setTitle("Modifier contacte");
		this.setVisible(true);
		this.setContentPane(pan);
	} //fin du constructeur
	
	public String getJtf1(){
		return jtf1.getText();
	}
	public String getJtf2(){
		return jtf2.getText();
	}
	public String getJtf3(){
		return jtf3.getText();
	}
	public String getJtf4(){
		return jtf4.getText();
	}
	public String getJtf5(){
		return jtf5.getText();
	}
	public String getJtf6(){
		return jtf6.getText();
	}
	public String getJtf7(){
		return jtf7.getText();
	}
	public String getCombo() {
		ItemAction ia=new ItemAction();
		String comboT=ia.getComboText();
		return comboT;
	}
	//if the button ok is clicked execute a methode
	//in the controller named actionPerformed
	/**
	 * 
	 * @param listenForOKButton
	 * Si je clique sur le boutton ok, 
	 * la methode actionPerformer qui se trouve dans 
	 * la classe modifieContactController est executé
	 */
		
		public void modifierContactListener(ActionListener listenForOKButton){
			b.addActionListener(listenForOKButton);
		}
		
		public void cancelContactListener(ActionListener listenForOKButton){
			cancel.addActionListener(listenForOKButton);
		}
		
		class ItemAction implements ActionListener{
			public String comboText;

			public String getComboText() {
				 comboText=combo.getSelectedItem().toString();
				return comboText;
			}

			public void actionPerformed(ActionEvent e){
				String comboText=combo.getSelectedItem().toString();
				System.out.println(comboText);
			}
		}
		
		
}
